﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Serialization.Formatters;
using System.Collections;
using System.Runtime.Remoting.Channels.Tcp;
using System.Net.Sockets;

namespace Game.Client
{
    static class Program
    {
        public static int Port { get; private set; }
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main()
        {
            try
            {
                //RemotingConfiguration.Configure("Client.exe.config", false);
                Port = (int)DateTime.Now.Subtract(DateTime.Now.Date).TotalSeconds / 2 + 21800;

                // Creating a custom formatter for a TcpChannel sink chain.
                BinaryServerFormatterSinkProvider provider = new BinaryServerFormatterSinkProvider();
                provider.TypeFilterLevel = TypeFilterLevel.Full;
                // Creating the IDictionary to set the port on the channel instance.
                IDictionary props = new Hashtable();
                props["port"] = Port;
                // Pass the properties for the port setting and the server provider in the server chain argument. (Client remains null here.)
                TcpChannel channel = new TcpChannel(props, null, provider);

                System.Runtime.Remoting.Channels.ChannelServices.RegisterChannel(channel, false);
                RemotingConfiguration.RegisterWellKnownServiceType(typeof(RemoteServer), "testuri", WellKnownObjectMode.Singleton);
            }
            catch (RemotingException)
            { }

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
        }
    }
}
